package com.abss.vote.mapper;

import com.abss.vote.model.*;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

@Mapper
@Repository
public interface PrizeMapper {

    Integer addPrize(Prize prize);

    List<Prize> getAllPrize();

    List<String> getPrizeNames();

    MpInfo getMpInFo(String serverId);

//    int setMpInFo(MpInfo mpInfo);

    @Select("select * from PRIZE where ACTIVITY_ID=${activity_id} order by ORDER_NUM,PRIZE_ID")
    List<Prize> getPrizeListByActivityId(@Param("activity_id")int activity_id);

    @Select("SELECT * from PRIZE  where PRIZE_ID=#{prize_id}")
    Prize getPrizeByid(@Param("prize_id")Integer prize_id);

    @Select("SELECT count(*) from [WORK]  where PRIZE_ID=#{prize_id} and ACTIVITY_ID = #{activity_id} and DELETED=0")
    int getCountWork(@Param("prize_id")Integer prize_id,@Param("activity_id") int activity_id);

    @Select("SELECT PRIZE_NAME from PRIZE  where PRIZE_ID=#{prize_id}")
    String getPrizeName(@Param("prize_id")Integer prize_id);

    @Select("SELECT * from [WORK] w LEFT JOIN USER_REG_INFO u on w.ACTIVITY_ID=u.ACTIVITY_ID and w.USER_ID=u.USER_ID\n" +
            "LEFT JOIN PRIZE p on w.PRIZE_ID=p.PRIZE_ID where p.PRIZE_ID =#{prize_id} and w.DELETED=0 and u.DELETED=0")
    List<UserWorkVo> getPrizeOne(@Param("prize_id")Integer prize_id);

    @Delete("delete from PRIZE where PRIZE_ID=${prize_id}")
    int deletePrizeByPrizeId(@Param("prize_id")Integer prize_id);

    int setMpInFo(@Param("access_token") String access_token,@Param("mp_app_id") String mp_app_id,@Param("mp_app_secret") String mp_app_secret,@Param("last_update_time") Date last_update_time);

    int setMpInFos(@Param("access_token")String access_token,@Param("mp_app_id") String mp_app_id,@Param("mp_app_secret") String mp_app_secret,@Param("last_update_time") String last_update_time,@Param("last_update_milliseconds") String last_update_milliseconds);

    int setMpInFocs(MpInfo mpInfo1);
}
